package me.xuym.crawler.t66y;

import com.cbs.java.component.application.Application;
import com.cbs.java.component.application.BaseArgs;
import me.xuym.crawler.Processor;
import me.xuym.crawler.Task;
import me.xuym.crawler.simpleextension.dispatcher.SimpleDebugListDispatcher;
import me.xuym.crawler.simpleextension.processor.filter.SimpleBlackListFilter;
import me.xuym.crawler.simpleextension.processor.filter.SimpleCachedMySQLListFilter;
import me.xuym.crawler.simpleextension.processor.filter.SimpleWhiteListFilter;

/**
 * Created by broche on 07/09/2017.
 */
public class MyApplication extends Application {
    private BaseArgs baseArgs = new BaseArgs();

    public MyApplication(String[] args) {
        super(args);
    }

    @Override
    public boolean isDebug() {
        return false;
    }

    @Override
    public String applicationName() {
        return "crawler/t66y";
    }

    @Override
    public BaseArgs getArgs() {
        return baseArgs;
    }

    @Override
    public void start() {
        super.start();
        try {
            Task task = new Task(this);
            Processor processor = task.load(new T66yLoader(this))
                    .process(new T66yConvertor(this))
                    .process(new SimpleBlackListFilter(this))
                    .process(new SimpleWhiteListFilter(this))
                    .process(new SimpleCachedMySQLListFilter(this))
                    .process(new T66yDownloadUrlConvertor(this))
                    .process(new SimpleCachedMySQLListFilter(this));
            if (isDebug()) {
                processor.dispatch(new SimpleDebugListDispatcher(this));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        MyApplication application = new MyApplication(args);
        application.start();
    }
}
